// 班次
import {request} from "../request";
import {utils} from "../../common/utils";

// 新增
export function addShif(arr){
    console.log("arr -> ", arr)
    return request({
        url:"/shift",
        method:'post',
        data: arr
    })
}

// 查询
export function selAll(){
    return request({
        url:"/shift",
        method:'get'
    })
}

// 修改状态 - 启用
export function uptZero(val){
    let arr = [];
    if (val.length > 1){
        arr = val
    }else{
        arr.push(val);
    }
    console.log("修改 ",arr)
    return request({
        url:"/shiftPhase/zero/"+arr,
        method:'put',
    })
}

// 修改状态 - 禁用
export function uptOne(val){
    let arr = [];
    if (val.length > 1){
        arr = val
    }else{
        arr.push(val);
    }
    console.log("修改 ",arr)
    return request({
        url:"/shiftPhase/one/"+arr,
        method:'put',
    })
}

// 删除
export function delAll(val){
    console.log("删除",val)
    return request({
        url:"/shift/"+val,
        method:'delete'
    })
}

// 批量新增 排班人员
export function addListBySch(wsp){

    let arr = {
        closureDate:null,
        initiateDate:null,
        shiftId:null,
        workIds:[]
    };
    arr.closureDate = wsp.closureDate
    arr.initiateDate = wsp.initiateDate
    arr.shiftId = wsp.shiftId
    arr.workIds = wsp.workIds

    console.log("arr -> ", arr)

    return request({
        url:"/workSchedule",
        method:'post',
        data:arr
    })
}

// 查询排班
export function getListScheduling(condition,pagination){
    let datasel = 0;
    let statussel = 0;
    let pageNum = 1;
    let pageSize= 10;

    if (!condition.isEmpty){
        datasel = condition.riqisel
        statussel = condition.pbqk
    }
    if (!pagination.isEmpty){
        pageNum = pagination.pageNum
        pageSize = pagination.pageSize
    }

    return request({
        url:"/workSchedule",
        method:'get',
        params:{
            pageNum,
            pageSize,
            datasel,
            statussel
        }
    })
}

// 取消排班
export function delByWorids(val){
    let workIds = null
    if (val instanceof Array){
        workIds = utils.joinArrayReqParam(val,'rids');
    }else{
        let a = []
        a.push(val)
        workIds = utils.joinArrayReqParam(a,'rids');
    }
    console.log("wids -> ", workIds)
    return request({
        url:"/workSchedule/" + workIds,
        method:'delete'
    })
}

